package com.mingke.auth.controller;


import com.mingke.common.entity.UserEntity;
import com.mingke.common.service.GroupService;
import com.mingke.common.transfer.CreateGroupTO;
import com.mingke.common.transfer.JoinGroupTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/group")
public class GroupController {
    @Autowired
    private GroupService groupService;

    /**
     * @apiNote 根据群名创建群聊
     * @param createGroupTO
     * @return 群ID
     */
    @PostMapping("create")
    public String createGroup(@RequestBody CreateGroupTO createGroupTO) {
        Integer groupId = groupService.create(createGroupTO);
        return groupId.toString();
    }

    /**
     * @apiNote 加入指定群组
     * @param joinGroupTO
     * @return 加入结果
     */
    @PostMapping("join")
    public Integer joinGroup(@RequestBody JoinGroupTO joinGroupTO) {
        Integer result = groupService.join(joinGroupTO);
        return result;
    }

    /**
     * @apiNote 获取到群友的ID
     * @param groupID
     * @return
     */
    @GetMapping("mates")
    public List<UserEntity> matesOfGroup(@RequestParam Integer groupID) {
        List<UserEntity> matesId = groupService.mates(groupID);
        return matesId;
    }
}
